package com.example.newstudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.newstudent.dao.bulletinDao;
import com.example.newstudent.entity.bulletin;
import com.example.newstudent.service.bulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class bulletinIpml implements bulletinService {
    @Autowired bulletinDao bulletinDao;

    @Override
    public List<bulletin> selectBulletin() {
        return bulletinDao.selectList(null);
    }

    @Override
    public List<bulletin> punishBulletin(bulletin bulletin) {
        LocalDateTime localDateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 使用formatter将LocalDateTime转换为字符串
        String formattedDateTime = localDateTime.format(formatter);
        bulletin.setTime(formattedDateTime);
        bulletinDao.insert(bulletin);
        return bulletinDao.selectList(null);
    }

    @Override
    public void deleteBulletin(int id) {
        QueryWrapper<bulletin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        bulletinDao.delete(queryWrapper);
    }
}
